package triInstance;

import transaction.Transaction;
import triBasic.*;
import triStorage.*;

public class NodeSnapshot {
	
	private int nodeId;	
	
	private int inodePageId;
	
	private int setInodePageId;
	
	private String tagName;
	
	public NodeSnapshot() {
		nodeId = -1;
		inodePageId = -1;
		setInodePageId = -1;
		tagName = null;
	}
	
	public NodeSnapshot(int nodeId, String tagName, int inodePageId, int setInodePageId) {
		this.nodeId = nodeId;
		this.tagName = tagName;
		this.inodePageId = inodePageId;
		this.setInodePageId = setInodePageId;
	}
	
	public int getNodeId() {
		return this.nodeId;
	}
	
	public String getTagName() {
		return this.tagName;
	}
	
	public int getInodePageId() {
		return this.inodePageId;
	}
	
	public int getSetInodePageId() {
		return this.setInodePageId;
	}
	
	public NodeInfo copy() {
		return new NodeInfo(nodeId, tagName);
	}
	
	public boolean load(IReader reader) {
		Integer test = reader.readInt();
		if (test == null)
			return false;
		
		this.nodeId = test;
		this.tagName = reader.readString();
		this.inodePageId = reader.readInt();
		this.setInodePageId = reader.readInt();
		if (nodeId < 0 || inodePageId < 0 || setInodePageId < 0 || tagName == null)
			return false;
		return true;
		
	}
	
	public void flush(IWriter writer, Transaction tx) {
		writer.appendInt(nodeId, tx);
		writer.appendString(tagName, tx);
		writer.appendInt(inodePageId, tx);
		writer.appendInt(setInodePageId, tx);
	}

}
